Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpreter #4

Merged
merged 37 commits into from
Aug 1, 2024
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
bacbb78
initial draft
ascandone Jul 22, 2024
7499d3f
handling vars
ascandone Jul 22, 2024
b9ed59d
impl inorder src
ascandone Jul 23, 2024
a9a3528
WIP
ascandone Jul 23, 2024
d7b55c2
Merge branch 'main' into experiment/interpreter
ascandone Jul 29, 2024
b966ba4
implemented allotted destination
ascandone Jul 29, 2024
d937159
implemented remaining in allotment
ascandone Jul 29, 2024
a401e2c
added todo tests
ascandone Jul 29, 2024
2d007db
impl new test
ascandone Jul 29, 2024
b790501
impl send from world
ascandone Jul 29, 2024
9b393bf
add new test
ascandone Jul 29, 2024
b707344
add new test
ascandone Jul 29, 2024
2cfac3c
impl new test
ascandone Jul 29, 2024
6012735
refactored literals evaluation
ascandone Jul 29, 2024
0d290ac
added track balance tests
ascandone Jul 30, 2024
0ba27a4
Merge branch 'main' into experiment/interpreter
ascandone Jul 30, 2024
ad3947d
implemented source allotment
ascandone Jul 30, 2024
a4dc47e
refactored allotment code
ascandone Jul 30, 2024
dbbdd91
refactor
ascandone Jul 30, 2024
b196366
cleaned up code
ascandone Jul 30, 2024
4a208b7
implemented cap source
ascandone Jul 30, 2024
f2a9f33
minor
ascandone Jul 30, 2024
99ee840
impl inorder dest
ascandone Jul 30, 2024
f0611fb
unskipped test
ascandone Jul 31, 2024
1d2e6ba
impl unbounded overdraft
ascandone Jul 31, 2024
4d8f0e6
refactor
ascandone Jul 31, 2024
88a72f2
minor
ascandone Jul 31, 2024
82856bd
better error handling
ascandone Jul 31, 2024
d928731
better error handling
ascandone Jul 31, 2024
7e53c9d
better err handling
ascandone Jul 31, 2024
e90754c
defined more runtime errs
ascandone Jul 31, 2024
8bb68ff
added more runtime errs
ascandone Aug 1, 2024
2b1f088
better args parsing
ascandone Aug 1, 2024
9c60aa7
better errors
ascandone Aug 1, 2024
0a0a4d2
quick and dirty run cli
ascandone Aug 1, 2024
e64eb15
handling run flags
ascandone Aug 1, 2024
0d6b63b
printing postings and data
ascandone Aug 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
quick and dirty run cli
ascandone committed Aug 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 0a0a4d2adaebeecaf64811e3998af1840f49c20d
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ func Execute(options CliOptions) {

rootCmd.AddCommand(lspCmd)
rootCmd.AddCommand(checkCmd)
rootCmd.AddCommand(getRunCmd())

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
65 changes: 65 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package cmd

import (
"fmt"
"numscript/interpreter"
"numscript/parser"
"os"

"github.com/spf13/cobra"
)

var runVariablesPath string
var runBalancesPath string
var runMetaPath string

func run(path string) {
content, err := os.ReadFile(path)
if err != nil {
os.Stderr.Write([]byte(err.Error()))
return
}

parseResult := parser.Parse(string(content))
if len(parseResult.Errors) != 0 {
// TODO better output
fmt.Printf("Got errors while parsing\n")
return
}

program := parseResult.Value

store := interpreter.StaticStore{}
// TODO vars, store, meta
result, err := interpreter.RunProgram(program, nil, store, nil)
if err != nil {
panic(err)
}

fmt.Println("Postings:")
for _, posting := range result.Postings {
fmt.Printf("{ from = @%s, amount = [%s %s], to = %s}\n", posting.Source, posting.Asset, posting.Amount.String(), posting.Destination)
}
}

func getRunCmd() *cobra.Command {
cmd := cobra.Command{
// Keep the command as hidden as long as it's unstable
Hidden: true,

// Other ideas: simulate, eval, exec
Use: "run",
Short: "Evaluate a numscript file",
Long: "Evaluate a numscript file. This command is unstable and still being developed",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
path := args[0]
run(path)
},
}

cmd.Flags().StringVarP(&runVariablesPath, "variables", "v", "", "Path of a json file containing the variables")
cmd.Flags().StringVarP(&runBalancesPath, "balances", "b", "", "Path of a json file containing the balances")
cmd.Flags().StringVarP(&runMetaPath, "meta", "m", "", "Path of a json file containing the accounts metadata")
return &cmd
}