Skip to content

Commit

Permalink
General bugfixes/improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
shogundevel committed Mar 30, 2023
1 parent c4eff00 commit 2b35325
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 28 deletions.
Binary file modified bin/tool
Binary file not shown.
15 changes: 10 additions & 5 deletions make
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@

echo ???
:boot

:hello
echo Hello, world!
compile c include/system.shk temp/out.bin
link c temp/out.bin null temp/system.shar

:bye
echo Bye, world!
compile c include/shark.shk temp/out.bin
link c temp/out.bin null temp/gameshark.shar

compile c sharktool.shk temp/out.bin
link c temp/out.bin sharktool temp/tool

unlink temp/out.bin
36 changes: 35 additions & 1 deletion sharkenv/builtin.shk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
##
################################################################################

import system.io: puts, printf
import system.io: puts, printf, open
import system.exit -> libexit
import system.path
import system.string
Expand Down Expand Up @@ -53,3 +53,37 @@ function exit(args)

function echo(args)
printf("%\n", [string::join(" ", util::slice(args, 1, sizeof(args)))])

function install(args)
if sizeof(args) != 2 then
puts("usage: install <filename>\n\tinstalls a file locally, so it can be cloned later.")
return
var base = path::get_base(args[0])
var origin = args[1]
var source = open(origin, "rb")
if source == null then
printf("can't open input file '%'.", [origin])
return
var libs = path::join(base, "libs")
path::mkdir(libs)
var install_path = path::join(libs, path::get_tail(origin))
var output = open(install_path, "wb")
while not source.at_end() do
output.puts(source.read(256))

function clone(args)
if sizeof(args) != 3 then
puts("usage: clone <source> <target>\n\tclones a file from the local repository.")
return
var base = path::get_base(args[0])
var origin = path::join(path::join(base, "libs"), args[1])
var target = args[2]
var source = open(origin, "rb")
if source == null then
printf("in clone operation: can't open requested file '%'.", [origin])
return
var output = open(target, "wb")
if output == null then
printf("in clone operation: can't reach <target> file '%', operation aborted.", [target])
while not source.at_end() do
output.puts(source.read(256))
16 changes: 16 additions & 0 deletions sharkmake.shk
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ import system.string

import sharkenv.core

import sharkc
import sharklink
import sharkemu
import sharkmake
import sharkzip

function play(args)
sharkemu::play()

core::command_table["compile"] = sharkc::main
core::command_table["link"] = sharklink::main
core::command_table["run"] = sharkemu::main
core::command_table["play"] = play
core::command_table["make"] = sharkmake::main
core::command_table["zip"] = sharkzip::main

function main(args)
core::exec_name = args[0]
var source = open("make", "r")
Expand Down
36 changes: 14 additions & 22 deletions sharktool.shk
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import sharkenv
import sharkmake
import sharkzip

import sharkenv.builtin: install, clone

function main(args)
if sizeof(args) < 2 then
printf("usage: % <command> <args>\n", [args[0]])
Expand All @@ -44,11 +46,11 @@ function main(args)
puts("\trun <filename> <args>\n")
puts("\tcompile <target> <filename> <out>\n")
puts("\tlink <target> <source> <main> <out> <libs>\n")
puts("\tmake [action]\n")
puts("\tbuild <filename> <out> <libs>\n")
puts("\tmake [action]\n")
puts("\tzip <source> <target>\n")
puts("\tinstall <libs>\n")
puts("\tuninstall <libs>\n")
puts("\tinstall <filename>\n")
puts("\tclone <source> <target>\n")
puts("(no command specified, now entering sharkenv)\n")
sharkenv::main([args[0]])
return
Expand All @@ -70,6 +72,15 @@ function main(args)
else if command == "make" then
args[0] << format("% %", [filename, command])
sharkmake::main(args)
else if command == "zip" then
args[0] << format("% %", [filename, command])
sharkzip::main(args)
else if command == "install" then
args[0] << format("% %", [filename, command])
install(args)
else if command == "clone" then
args[0] << format("% %", [filename, command])
clone(args)
else if command == "build" then
if sizeof(args) < 2 then
printf("usage: % build <filename> <out> <libs>\n", [filename])
Expand All @@ -84,24 +95,5 @@ function main(args)
extend(link_args, libs)
sharklink::main(link_args)
unlink(bin)
else if command == "zip" then
args[0] << format("% %", [filename, command])
sharkzip::main(args)
else if command == "install" then
for lib in args do
if get_ext(lib) != ".shar" then
printf("can't install invalid library file '%', expected a shark archive (.shar).\n", [lib])
else
var source = sharklink::fopen(lib, "rb")
var target = sharklink::fopen(join(base, get_tail(lib)), "wb")
sharklink::fread(source, target)
target.close()
else if command == "uninstall" then
for lib in args do
if get_ext(lib) != ".shar" then
printf("can't uninstall invalid library file '%', expected a shark archive (.shar).\n", [lib])
else
if not unlink(join(base, lib)) then
printf("unknown library file '%'.\n", [lib])
else
printf("unknown command '%'.", [command])

0 comments on commit 2b35325

Please sign in to comment.