wasm: direct platform, wam memory
authorJoel Martin <github@martintribe.org>
Mon, 15 Apr 2019 05:57:59 +0000 (00:57 -0500)
committerJoel Martin <github@martintribe.org>
Mon, 15 Apr 2019 05:57:59 +0000 (00:57 -0500)
- Rename platform_os.wam to platform_direct.wam and update the direct
  interface to use printline instead of fputs/stdout.
- Update to wamp 1.0.7 and new memory/memoryBase semantics: in
  platform_direct and platform_libc, import memory and memoryBase
  rather than relying on wamp to add it because wamp add direct memory
  and memoryBase defintions (not imports) if the program doesn't
  already define or import memory/memoryBase.
- Simplify entry point logic by moving it into the platform files.

15 files changed:
wasm/Makefile
wasm/package.json
wasm/platform_direct.wam [moved from wasm/platform_os.wam with 75% similarity]
wasm/platform_libc.wam
wasm/step0_repl.wam
wasm/step1_read_print.wam
wasm/step2_eval.wam
wasm/step3_env.wam
wasm/step4_if_fn_do.wam
wasm/step5_tco.wam
wasm/step6_file.wam
wasm/step7_quote.wam
wasm/step8_macros.wam
wasm/step9_try.wam
wasm/stepA_mal.wam

index cd30392..dc92010 100644 (file)
@@ -1,4 +1,4 @@
-MODE ?= $(if $(filter node js wace_fooboot warpy,$(wasm_MODE)),os,libc)
+MODE ?= $(if $(filter node js wace_fooboot warpy,$(wasm_MODE)),direct,libc)
 
 WASM_AS ?= wasm-as
 WAMP ?= node_modules/.bin/wamp
index 3f19a29..2260256 100644 (file)
@@ -3,7 +3,7 @@
     "version": "0.0.1",
     "description": "Make a Lisp (mal) language implemented in WebAssembly",
     "dependencies": {
-        "@kanaka/wamp": "1.0.6",
+        "@kanaka/wamp": "1.0.7",
         "ffi-napi": "^2.4.4",
         "text-encoding": "0.6.4"
     }
similarity index 75%
rename from wasm/platform_os.wam
rename to wasm/platform_direct.wam
index cb76c7f..a8e92b5 100644 (file)
@@ -1,8 +1,10 @@
 (module $platform_os
 
+  (import "env" "memory" (memory 256))
+  (import "env" "memoryBase" (global $memoryBase i32))
+
   (import "env" "exit"        (func $lib_exit (param i32)))
-  (import "env" "stdout"      (global $lib_stdout i32))
-  (import "env" "fputs"       (func $lib_fputs (param i32 i32) (result i32)))
+  (import "env" "printline"   (func $lib_printline (param i32) (result i32)))
   (import "env" "readline"    (func $lib_readline (param i32 i32 i32) (result i32)))
   (import "env" "read_file"   (func $lib_read_file (param i32 i32) (result i32)))
   (import "env" "get_time_ms" (func $lib_get_time_ms (result i32)))
@@ -17,7 +19,8 @@
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
   (func $print (param $addr i32)
-    (drop ($lib_fputs $addr (global.get $lib_stdout))))
+    (drop ($lib_printline $addr))
+  )
 
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
     ($lib_get_time_ms)
   )
 
+  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+  (func $entry (param $argc i32 $argv i32)
+    ($init_memory)
+    ($lib_exit ($main $argc $argv))
+  )
+
+  (export "_main" (func $entry))
+
 )
index 351f1f4..f1d0a71 100644 (file)
@@ -1,12 +1,13 @@
 (module $platform_libc
 
-  (import "env" "exit" (func $lib_exit (param i32)))
-
-  (import "env" "stdout" (global $lib_stdout i32))
-  (import "env" "fputs" (func $lib_fputs (param i32 i32) (result i32)))
-
-  (import "env" "free" (func $lib_free (param i32)))
-  (import "env" "readline" (func $lib_readline (param i32) (result i32)))
+  (import "env" "memory" (memory 256))
+  (import "env" "memoryBase" (global $memoryBase i32))
+
+  (import "env" "exit"        (func $lib_exit (param i32)))
+  (import "env" "stdout"      (global $lib_stdout i32))
+  (import "env" "fputs"       (func $lib_fputs (param i32 i32) (result i32)))
+  (import "env" "readline"    (func $lib_readline (param i32) (result i32)))
+  (import "env" "free"        (func $lib_free (param i32)))
   (import "env" "add_history" (func $lib_add_history (param i32)))
 
   ;; read_file defintions / FFI information
                                (i32.div_u $usecs 1000)))
     $msecs
   )
+
+  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+  (func $entry (param $argc i32 $argv i32)
+    ($init_memory)
+    ($lib_exit ($main $argc $argv))
+  )
+
+  (export "_main" (func $entry))
+
 )
index 354d46c..6814041 100644 (file)
@@ -19,7 +19,7 @@
     ($PRINT ($EVAL ($READ $line) 0))
   )
 
-  (func $main (result i32)
+  (func $main (param $argc i32 $argv i32) (result i32)
     ;; Constant location/value definitions
     (LET $line (STATIC_ARRAY 201))
 
     0
   )
 
-
-  (export "_main" (func $main))
-  (export "__post_instantiate" (func $init_printf_mem))
+  ;; init_memory is provided by mem.wam in later steps but we just
+  ;; printf in step0 so provide init_memory that just calls that
+  (func $init_memory
+    ($init_printf_mem)
+  )
 )
 
index a41d333..19e330d 100644 (file)
@@ -34,7 +34,7 @@
     $ms
   )
 
-  (func $main (result i32)
+  (func $main (param $argc i32 $argv i32) (result i32)
     (LET $line (STATIC_ARRAY 201)
          $res  0)
 
@@ -77,8 +77,5 @@
     0
   )
 
-
-  (export "_main" (func $main))
-  (export "__post_instantiate" (func $init_memory))
 )
 
index 0ce9712..fdf161a 100644 (file)
       (i32.div_s ($VAL0 ($MEM_VAL1_ptr $args))
                  ($VAL0 ($MEM_VAL1_ptr ($MEM_VAL0_ptr $args))))))
 
-  (func $main (result i32)
+  (func $main (param $argc i32 $argv i32) (result i32)
     (LET $line (STATIC_ARRAY 201)
          $res 0 $repl_env 0)
 
     0
   )
 
-
-  (export "_main" (func $main))
-  (export "__post_instantiate" (func $init_memory))
 )
 
index df04633..c756dff 100644 (file)
     ($PR_MEMORY -1 -1)
     ($INC_REF (global.get $NIL)))
 
-  (func $main (result i32)
+  (func $main (param $argc i32 $argv i32) (result i32)
     (LET $line (STATIC_ARRAY 201)
          $res 0 $repl_env 0)
 
     0
   )
 
-
-  (export "_main" (func $main))
-  (export "__post_instantiate" (func $init_memory))
 )
 
index da16f57..c984bf5 100644 (file)
     $ms
   )
 
-  (func $main (result i32)
+  (func $main (param $argc i32 $argv i32) (result i32)
     (LET $line (STATIC_ARRAY 201)
          $res 0 $repl_env 0 $ms 0)
 
     0
   )
 
-
-  (export "_main" (func $main))
-  (export "__post_instantiate" (func $init_memory))
 )
 
index 20d8fda..1268d46 100644 (file)
     $ms
   )
 
-  (func $main (result i32)
+  (func $main (param $argc i32 $argv i32) (result i32)
     (LET $line (STATIC_ARRAY 201)
          $res 0 $repl_env 0 $ms 0)
 
     0
   )
 
-
-  (export "_main" (func $main))
-  (export "__post_instantiate" (func $init_memory))
 )
 
index e5b56a6..373f6ef 100644 (file)
     0
   )
 
-
-  (export "_main" (func $main))
-  (export "__post_instantiate" (func $init_memory))
 )
 
index e609a56..41efd52 100644 (file)
     0
   )
 
-
-  (export "_main" (func $main))
-  (export "__post_instantiate" (func $init_memory))
 )
 
index ff042d0..82fa716 100644 (file)
     0
   )
 
-
-  (export "_main" (func $main))
-  (export "__post_instantiate" (func $init_memory))
 )
 
index 31567f1..904f11e 100644 (file)
     0
   )
 
-
-  (export "_main" (func $main))
-  (export "__post_instantiate" (func $init_memory))
 )
 
index 3437620..5dfb4bb 100644 (file)
     0
   )
 
-
-  (export "_main" (func $main))
-  (export "__post_instantiate" (func $init_memory))
 )